package com.fengye.revoker;

import com.fengye.model.RemoteResponse;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @Author fengye
 * @Date 2023/2/14 19:27
 **/
public class NettyClientInvokeHandler extends SimpleChannelInboundHandler<RemoteResponse> {

    public NettyClientInvokeHandler() {
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        ctx.flush();
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, RemoteResponse remoteResponse) throws Exception {
        // 将Netty异步返回结果存入阻塞队列，以便调用端同步获取
        RevokerResponseHolder.putResultValue(remoteResponse);
    }


}
